const helper = require('./helper');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpackMerge = require('webpack-merge'); // used to merge webpack configs
const commonConfig = require('./webpack.config.common');
/**
 * Webpack Constants
 */
const ENV = process.env.ENV = process.env.NODE_ENV = 'development';
const OUT_PUT_DIR = ENV;

/**
 * Webpack configuration
 *
 * See: http://webpack.github.io/docs/configuration.html#cli
 */
module.exports = function (options) {
  let config = webpackMerge.smartStrategy({
    entry: 'prepend', // or 'replace', defaults to 'append' 
    'module.loaders': 'defaults',
    'plugins': 'append'
  })(commonConfig({
    env: ENV,
    outPutDir: OUT_PUT_DIR
  }),
    {
      entry: {
        'ZZpolyfills': helper.root('src', 'polyfills.ts'),
        'main': helper.root('src', 'main.ts'),
        'style': helper.root('src', 'styles.css'),
      },

      output: {
        path: helper.root(OUT_PUT_DIR),
        filename: 'js/[name].bundle.js',
        chunkFilename: 'js/[id].chunk.bundle.js'
      },

      resolveLoader: {
        alias: {
          "do-nothiing-loader": require.resolve(helper.root('config', 'loaders', 'do-nothiing-loader')),
          "my-source-map-loader": require.resolve(helper.root('config', 'loaders', 'my-source-map-loader')),
        }
      },

      module: {
        loaders: [{
          test: /.ts$/,
          loaders: ['do-nothiing-loader'],
          exclude: /node_modules/,
          include: helper.root('src')
        },
        ]
      },

      plugins: [
        new HtmlWebpackPlugin({
          template: 'src/index.html'
        }),

        new CopyWebpackPlugin([{
          from: helper.root('src', 'assets'),
          to: helper.root('src', 'assets')
        },
        {
          from: helper.root('src', 'styles.css'),
          to: helper.root('src', 'assets', 'styles.css')
        }])
      ],

      devtool: 'cheap-module-source-map',

    });
  console.log(config.module.loaders[0].loaders);
  return config;
}
